package com.trsj.lnsj.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.trsj.lnsj.common.DataResponse;
import com.trsj.lnsj.common.MsgStatus;
import com.trsj.lnsj.entity.GroupDTO;
import com.trsj.lnsj.entity.NoticeDTO;
import com.trsj.lnsj.entity.NoticeStatusDTO;
import com.trsj.lnsj.service.imp.GroupService;

import io.swagger.annotations.Api;

/**
 * 
 * <p>
 * Title: GroupController.java
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2018
 * </p>
 * 
 * <p>
 * Company: 七色环
 * </p>
 * 
 * @author longky
 * 
 * @date 2018年8月30日
 * 
 * @version 1.0
 * 
 */
@RestController
@Api(value="群组接口",tags={"群组相关api"})
@RequestMapping(value = "/api/group/*")
@CrossOrigin
public class GroupController {
    @Autowired
    GroupService groupService;

    @RequestMapping(value = "/api/group/list")
    public DataResponse GroupList(@RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        pageNum = pageNum - 1;
        PageRequest pageRequest = new PageRequest(pageNum, pageSize);
        Page<GroupDTO> page = groupService.listGroup(pageRequest);
        return new DataResponse(MsgStatus.STATUS_OK, page);
    }

    /**
     * 
     * @param pageNum
     * @param pageSize
     * @param gid 群号
     * @return
     */
    @RequestMapping(value = "/notice/list")
    public DataResponse noticeList(@RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,@RequestParam(required=true) long gid) {
        pageNum = pageNum - 1;
        PageRequest pageRequest = new PageRequest(pageNum, pageSize);
        DataResponse resp = groupService.listNotice(pageRequest,gid);
        return resp;
    }

    /**
     * 
     * @param pageNum
     * @param pageSize
     * @param gid 群号
     * @return
     */
    @PostMapping(value = "/notice/save")
    public DataResponse noticeSave(NoticeDTO notice) {
        DataResponse resp = groupService.noticeSave(notice);
        return resp;
    }

    /**
     * 
     * @param id
     * @return
     */
    @PostMapping(value = "/notice/delete")
    public DataResponse noticeDel(int id) {
        DataResponse resp = groupService.noticeDel(id);
        return resp;
    }

    /**
     * 
     * @param id
     * @return
     */
    @PostMapping(value = "/notice/read")
    public DataResponse noticeRead(NoticeStatusDTO ns) {
        DataResponse resp = groupService.noticeRead(ns);
        return resp;
    }

}
